//
//  AppDelegate+JPush.m
//  YunGou
//
//  Created by macbook on 16/6/13.
//  Copyright © 2016年 macbook. All rights reserved.
//

#import "AppDelegate+JPush.h"
#import "JPUSHService.h"

static NSString *const Channel = @"Publish channel";

@implementation AppDelegate (JPush)
-(void)JpushApplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions appkey:(NSString *)appkey{
   // if ([UserDefaults objectForKey:@"isPush"] == nil) {
        if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
            //可以添加自定义categories
            [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |UIUserNotificationTypeSound |UIUserNotificationTypeAlert) categories:nil];
        } else {
            //categories 必须为nil
            [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert)categories:nil];
        }
   // }
    
    [JPUSHService setupWithOption:launchOptions appKey:appkey channel:Channel apsForProduction:FALSE];
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    [JPUSHService resetBadge];
    [application setApplicationIconBadgeNumber:0];
    [application cancelAllLocalNotifications];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    application.applicationIconBadgeNumber = 0;
}

- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
    [JPUSHService handleRemoteNotification:userInfo];
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
    [JPUSHService registerDeviceToken:deviceToken];
}
@end
